
function build(data){
	if(!validate(data))
		return ;
	var editable = false;
	if(data.type == 'edit' || data.type =='create') {
		$('#edit-panel .content').append("<form id='editor' method='post' action='"+(data.url?data.url:'')+"'></form>");
		editable = true;
	} else {
		$('#edit-panel .content').append("<div id='editor'></div>");
	}
	delete data.type;
	data = data.data;
	var properties = [];
	for(var i=0;i<data.length;i++){
		properties.push(complie(data[i]));
	}
	for(var i=0;i<properties.length;i++)
		$('#edit-panel .content #editor').append("<li id='li"+i+"'>"+properties[i].html+"</li>");
}

function validate(data) {
	//TODO
	return true;
}
function complie(data) {
	var _this = {editable:true, html:'<lable id="lable'+data.name+'">'+data.name+'</lable>'};
	switch(data.attribute.name){
	case 'id':
		_this.editable = false;
		_this.html += '<input type="text" scope="id" id="ed_'+data.name+'" name="'+data.name+'" value="'+(data.value? data.value:"")+'" disabled="disabled" />';
		break;
	case 'title':
		_this.html += '<input type="text" scope="title" id="ed_'+data.name+'" name="'+data.name+'" value="'+(data.value? data.value:"")+'" '+(data.attribute.editable? "":"disabled='disabled'")+ (data.attribute.size? "size='"+data.attribute.size+"'":"") +' />';
		break;
	case 'num': 
		_this.html += '<input type="text" id="ed_'+data.name+'" name="'+data.name+'" value="'+(data.value? data.value:"")+'" '+(data.attribute.editable? "":"disabled='disabled'")+ (data.attribute.size? "size='"+data.attribute.size+"'":"")+' />';
		break;
	case 'string': 
		if(data.attribute.type === 'text'){
			_this.html += '<textarea id="ed_'+data.name+'" name="'+data.name+'" cols="80" rows="'+ (data.attribute.size? (data.attribute.size/80):50) +'">'+(data.value? data.value:"")+'</textarea>';
		} else if(data.attribute.type === 'rich') {
			_this.html += '';
		} else
			_this.html += '<input type="text" id="ed_'+data.name+'" name="'+data.name+'" value="'+(data.value? data.value:"")+'" '+(data.attribute.editable? "":"disabled='disabled'")+ (data.attribute.size? "size='"+data.attribute.size+"'":"")+' />';
		break;
	case 'select': 
		if(data.attribute.type === 'choice'){
			var tmp = '<input type="radio" id="ed_'+data.name+'" name="'+data.name+'" ';
			var list = data.attribute.range.split(';');
			for(var i=0;i<list.length;i++) {
				var kv = list[i].split(":");
				_this.html += tmp + ' value="'+kv[1]+'" />&nbsp;'+kv[0];
			}
		} else {
			_this.html += '<select id="ed_'+data.name+'" name="'+data.name+'" >';
			var list = data.attribute.range.split(';');
			for(var i=0;i<list.length;i++) {
				var kv = list[i].split(":");
				_this.html += "<option value='"+kv[1]+"'>"+kv[0]+"</option>" 
			}
			_this.html += "</select>";
		}
		break;
	case 'image': 
		_this.html += '<img src="'+data.value+'" /><input type="text" id="ed_'+data.name+'" name="'+data.name+'" value="'+(data.value? data.value:"")+'" '+(data.attribute.editable? "":"disabled='disabled'")+ (data.attribute.size? "size='"+data.attribute.size+"'":"")+' />';
		break;
	case 'password': 
		break;
//	case '': 
//		break;
	default: break;
	}
	return _this;
}